package com.cjq.core.loadblance.impl;

import com.cjq.core.loadblance.LoadBalancer;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Random;

/**
 * @author CuiJQ
 * @date 2025/2/27 08:58
 * 随机策略
 */
@Component
public class RandomSelectLoadBalancer implements LoadBalancer {

    private final Random random = new Random();

    private final List<String> instances;

    public RandomSelectLoadBalancer(List<String> instances) {
        this.instances = instances;
    }

    @Override
    public String choose() {
        return instances.get(random.nextInt(instances.size()));
    }
}
